| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Lines | 40 |
| Ratio | 58.82 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import path from 'path' |
||
| 43 | export function publish(filePath, tplPath, json) { |
||
| 44 | var p = new Promise((resolve, reject) => { |
||
| 45 | abeExtend.hooks.instance.trigger('beforePublish', json, filePath, tplPath) |
||
| 46 | var p1 = new Promise((resolve) => { |
||
| 47 | cmsOperations.save.save( |
||
| 48 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 49 | tplPath, |
||
| 50 | json, |
||
| 51 | '', |
||
| 52 | 'draft', |
||
| 53 | null, |
||
| 54 | 'publish') |
||
| 55 | .then(() => { |
||
| 56 | resolve() |
||
| 57 | }).catch(function(e) { |
||
| 58 | console.error(e) |
||
| 59 | }) |
||
| 60 | }) |
||
| 61 | |||
| 62 | p1.then((resSave) => { |
||
| 63 | cmsOperations.save.save( |
||
| 64 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 65 | tplPath, |
||
| 66 | json, |
||
| 67 | '', |
||
| 68 | 'publish', |
||
| 69 | resSave, |
||
| 70 | 'publish') |
||
| 71 | .then((resSave) => { |
||
| 72 | var result |
||
| 73 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 74 | result = { |
||
| 75 | success: 0, |
||
| 76 | error: resSave.error |
||
| 77 | } |
||
| 78 | } else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 79 | result = resSave |
||
| 80 | } else if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 81 | result = { |
||
| 82 | success: 1, |
||
| 83 | json: resSave.json |
||
| 84 | } |
||
| 85 | } |
||
| 86 | abeExtend.hooks.instance.trigger('afterPublish', result) |
||
| 87 | Manager.instance.updateList() |
||
| 88 | resolve(result) |
||
| 89 | }).catch(function(e) { |
||
| 90 | console.error('post.js', e) |
||
| 91 | var result = { |
||
| 92 | success: 0, |
||
| 93 | error: 'publish error' |
||
| 94 | } |
||
| 95 | abeExtend.hooks.instance.trigger('afterPublish', result) |
||
| 96 | resolve(result) |
||
| 97 | }) |
||
| 98 | }).catch(function(e) { |
||
| 99 | console.error('post.js', e) |
||
| 100 | var result = { |
||
| 101 | success: 0, |
||
| 102 | error: 'publish error' |
||
| 103 | } |
||
| 104 | abeExtend.hooks.instance.trigger('afterPublish', result) |
||
| 105 | resolve(result) |
||
| 106 | }) |
||
| 107 | }) |
||
| 108 | View Code Duplication | ||
| 109 | return p |
||
| 110 | } |
||
| 111 | |||
| 199 | } |